package company.bytedance;

import java.util.*;

public class B1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeMap<Integer, Integer> dict = new TreeMap<>();
        int n = sc.nextInt();
        int m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int no = sc.nextInt();
            int score = sc.nextInt();
            dict.put(no, dict.getOrDefault(no, 0) + score);
        }
        NavigableMap<Integer, Integer> ans = dict.descendingMap();
        int i = 0;
        for (Map.Entry<Integer, Integer> e : ans.entrySet()) {
            if (i == m)
                break;
            System.out.print(e.getKey()+" ");
            i++;
        }
    }
}
